import axios from "axios";
export default function ajax(url, data = {}, type = "GET") {
  return new Promise((resolve, reject) => {
    let promise;
    if (type === 'GET') {
      promise = axios.get(url, {
        params: data
      })
    } else if (type === 'POST') {
      const token = sessionStorage.getItem('token');
      axios.defaults.headers.token = token;
      promise = axios.post(url, data)
    }

    promise.then(response => {
      resolve(response.data)
    }).catch(err => {
      reject(err)
    })
  })
}